import 'package:flutter/material.dart';
const BorderRadius defaultBorderRadius = BorderRadius.all(Radius.circular(8));
class RippleButton extends StatelessWidget {
  final Widget child;
  final VoidCallback? onTap;
  final ValueChanged<TapDownDetails>? onTapDown;
  final Color backgroundColor;
  final Color splashColor;
  final Color highlightColor;
  final BorderRadius? borderRadius;
  final BorderRadius? rippleRadius;
  final EdgeInsets? padding;
  final VoidCallback? onLongPress;

  const RippleButton({
    required this.child,
    this.onTap,
    this.onTapDown,
    this.backgroundColor = Colors.transparent,
    this.splashColor = Colors.black12,
    this.highlightColor = Colors.black26,
    this.borderRadius = defaultBorderRadius,
    this.rippleRadius,
    this.padding,
    this.onLongPress,
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    final isDisabled = onTap == null;

    return Material(
      color: isDisabled ? Colors.grey.shade300 : backgroundColor,
      borderRadius: borderRadius,
      child: InkWell(
        onTap: isDisabled ? null : onTap,
        onTapDown: isDisabled ? null : onTapDown,
        onLongPress: isDisabled ? null : onLongPress,
        splashColor: isDisabled ? Colors.transparent : splashColor,
        highlightColor: isDisabled ? Colors.transparent : highlightColor,
        borderRadius: rippleRadius ?? borderRadius,
        child: ConstrainedBox(
          constraints: const BoxConstraints(minWidth: 0.0, minHeight: 0.0),
          child: padding != null ? 
          Padding(
            padding: padding ?? EdgeInsets.zero,
            child: Opacity(
              opacity: isDisabled ? 0.5 : 1.0,
              child: child,
            ),
          ): 
          Opacity(
            opacity: isDisabled ? 0.5 : 1.0,
            child: child,
          )
        ),
      ),
    );
  }
}


